﻿using Autofac;
using DFGK.WMS.Common.JWT;
using DFGK_WMS.IRepository.IService;
using System.IdentityModel.Tokens.Jwt;
using System.Reflection;

namespace DFGJ.WMS_PDA.WebAPI.Utility
{
    public class AutoFacManage : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            var iapiservice = Assembly.Load("DFGK_WMS.Repository");

            builder.RegisterAssemblyTypes(iapiservice).Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces(); 

            builder.RegisterAssemblyTypes(iapiservice).Where(t => t.IsClass && !t.IsAbstract && t.GetInterfaces().Contains(typeof(IBaseService)))
                .AsSelf()
                .AsImplementedInterfaces()
                .PropertiesAutowired();

            builder.RegisterType<JwtSecurityTokenHandler>().SingleInstance();
            builder.RegisterType<TokenHelper>().SingleInstance();

        }
    }
}
